package category;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import yxnote.Category;
import yxnote.PMF;

public class Utils {
    public static List<Category> find() {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        Query query = pm.newQuery(Category.class);
        List<Category> categorys = (List<Category>) query.execute();
        return categorys;
    }
    
    public static Category find(String id) {
        Key key = KeyFactory.createKey(Category.class.getSimpleName(), Long.valueOf(id));
        return Utils.find(key);
    }
    
    
    public static Category find(Key key) {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            Category category = pm.getObjectById(Category.class, key);
            return category;
        } finally {
            pm.close();
        }
    }
    
    public static String getNameByKey(Key key) {
        return Utils.find(key).getName();
    }
}
